{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "using Unums"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5x5 Array{Unums.Ubound{3,4,UInt64},2}:\n",
       " (-0.7657852172851562,-0.765777587890625)     …   (0.35677337646484375,0.3567771911621094)     \n",
       "  (0.261260986328125,0.2612648010253906)         (-0.0039327144622802734,-0.003932654857635498)\n",
       " (-0.368988037109375,-0.3689842224121094)         (0.030651092529296875,0.030651330947875977)  \n",
       " (-0.1469268798828125,-0.1469249725341797)       (-0.3243675231933594,-0.32436370849609375)    \n",
       " (-0.08223628997802734,-0.08223533630371094)      (2.6845703125,2.684600830078125)             "
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X = map(Ubound34, randn(5,5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(\n",
       "5x5 Array{Unums.Ubound{3,4,UInt64},2}:\n",
       "   1.0                                        …  0.0\n",
       " (-0.34117889404296875,-0.34116363525390625)     0.0\n",
       "  (0.48183441162109375,0.48184967041015625)      0.0\n",
       "  (0.19186019897460938,0.19186782836914062)      0.0\n",
       "  (0.10738658905029297,0.10738945007324219)      1.0,\n",
       "\n",
       "5x5 Array{Unums.Ubound{3,4,UInt64},2}:\n",
       " (-0.7657852172851562,-0.765777587890625)  …   (0.35677337646484375,0.3567771911621094)  \n",
       "   0.0                                         (0.11778450012207031,0.11779308319091797) \n",
       "   0.0                                        (-0.16199684143066406,-0.16198158264160156)\n",
       "   0.0                                        (-0.8811798095703125,-0.88104248046875)    \n",
       "   0.0                                         (2.507293701171875,2.507537841796875)     ,\n",
       "\n",
       "[1,2,3,4,5])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "L,U,p = lu(X,Val{false}) # disable pivoting"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5x5 Array{Unums.Ubound{3,4,UInt64},2}:\n",
       " (-0.7657852172851562,-0.765777587890625)     …   (0.35677337646484375,0.3567771911621094)    \n",
       "  (0.26125335693359375,0.2612724304199219)       (-0.003940582275390625,-0.003924369812011719)\n",
       " (-0.36899566650390625,-0.3689765930175781)       (0.030637741088867188,0.030666351318359375) \n",
       " (-0.14693069458007812,-0.14692115783691406)     (-0.324493408203125,-0.3242340087890625)     \n",
       " (-0.08223819732666016,-0.08223342895507812)      (2.684417724609375,2.68475341796875)        "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "L*U"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5x5 Array{Unums.Ubound{3,4,UInt64},2}:\n",
       " (-7.62939453125e-6,7.62939453125e-6)        …  (-3.814697265625e-6,3.814697265625e-6)      \n",
       " (-1.1444091796875e-5,1.1444091796875e-5)       (-7.927417755126953e-6,8.344650268554688e-6)\n",
       " (-1.1444091796875e-5,1.1444091796875e-5)       (-1.3589859008789062e-5,1.52587890625e-5)   \n",
       " (-5.7220458984375e-6,5.7220458984375e-6)       (-0.00012969970703125,0.000133514404296875) \n",
       " (-2.86102294921875e-6,2.86102294921875e-6)     (-0.00018310546875,0.00018310546875)        "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "L*U - X"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(\n",
       "5x5 Array{Unums.Ubound{3,4,UInt64},2}:\n",
       "   1.0                                        …  0.0\n",
       " (-0.34117889404296875,-0.34116363525390625)     0.0\n",
       "  (0.19186019897460938,0.19186782836914062)      0.0\n",
       "  (0.48183441162109375,0.48184967041015625)      0.0\n",
       "  (0.10738658905029297,0.10738945007324219)      1.0,\n",
       "\n",
       "5x5 Array{Unums.Ubound{3,4,UInt64},2}:\n",
       " (-0.7657852172851562,-0.765777587890625)  …   (0.35677337646484375,0.3567771911621094) \n",
       "   0.0                                         (0.11778450012207031,0.11779308319091797)\n",
       "   0.0                                        (-0.42533111572265625,-0.4253120422363281)\n",
       "   0.0                                        (-0.31317138671875,-0.3131256103515625)   \n",
       "   0.0                                         (2.50732421875,2.507568359375)           ,\n",
       "\n",
       "[1,2,4,3,5])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Lp,Up,p = lu(X) # with pivoting"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5x5 Array{Unums.Ubound{3,4,UInt64},2}:\n",
       " (-7.62939453125e-6,7.62939453125e-6)        …  (-3.814697265625e-6,3.814697265625e-6)      \n",
       " (-1.1444091796875e-5,1.1444091796875e-5)       (-7.927417755126953e-6,8.344650268554688e-6)\n",
       " (-5.7220458984375e-6,5.7220458984375e-6)       (-1.52587890625e-5,1.9073486328125e-5)      \n",
       " (-1.1444091796875e-5,1.1444091796875e-5)       (-4.220008850097656e-5,4.57763671875e-5)    \n",
       " (-2.86102294921875e-6,2.86102294921875e-6)     (-0.00018310546875,0.000244140625)          "
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Lp*Up - X[p,:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Julia 0.4.3",
   "language": "julia",
   "name": "julia-0.4"
  },
  "language_info": {
   "file_extension": ".jl",
   "mimetype": "application/julia",
   "name": "julia",
   "version": "0.4.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
